package com.siteseat.crudeq.broker.v1.request;

import java.util.Set;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;

import com.siteseat.crudeq.broker.security.BrokerPermission;
import com.siteseat.crudeq.broker.transport.BrokerSession;

/**
 *
 */
public class V1UnsubscribeHandler extends V1AbstractRequestHandler {

  /**
   * {@inheritDoc}
   */
  @Override
  public void execute( BrokerSession session, byte reqId, Channel ch, ChannelBuffer input, short version )
          throws Exception {
    Set<Integer> mids = readQueueIdSet( session, ch, input, BrokerPermission.MESSAGE_SUBSCRIBE );
    if( mids != null && mids.size() > 0 ) {
      session.unsubscribe( mids );
    }
    
    responseOK( ch );
  }

}
